#include "Logger.h"

Logger::~Logger()
{
    log_queue_.shutdown();
    if (worker_thread_.joinable()) {
        worker_thread_.join();
    }
    if (log_file_.is_open()) {
        log_file_.close();
    }
}

std::string Logger::getCurrentTime()
{
    auto now = std::chrono::system_clock::now();
    std::time_t time = std::chrono::system_clock::to_time_t(now);
    char buffer[26];
    ctime_s(buffer, sizeof(buffer), &time);
    buffer[24] = '\0'; // 去掉末尾的换行符
    return std::string(buffer);
}

void Logger::processQueue()
{
    std::string msg;
    while (log_queue_.pop(msg)) {
        log_file_ << msg << std::endl;
        if (console_output_) {
            std::cout << msg << std::endl; // 输出到控制台
        }
    }
}
